package zwp.exercise.service.exercisedemo.chapterFour;

import java.util.*;

/**
 * @Author zwp14
 * @create 2025/11/24 22:20
 * @description 剧院售票练习题
 * 演播厅观众席有4行，每行10个座位，为了不影响观众的视角，屏蔽最左一列和最右一列的座位。模拟售票过程
 */
public class TheatreTicketSalesExerciseDemo {
    public static void main(String[] args) {
        // 屏蔽的列数
        int shieldNumOne = 1;
        int shieldNumTwo = 10;

        // 观众席行数和列数
        int numLine = 4;
        int numColumn = 10;

        // 设置缓存map，用于判断当前座位是否已经卖出
        Map<String,List<Integer>> cacheMap = new HashMap<>(numLine);
        for (int i = 1; i <= numLine; i++) {
            cacheMap.put(String.valueOf(i),new ArrayList<>());
            for (int j = 1; j <= numColumn; j++) {
                List<Integer> integerList = cacheMap.get(String.valueOf(i));
                // 如果是屏蔽的列数或者该座位已经卖出将跳过
                if ((j == shieldNumOne) || (j == shieldNumTwo) || integerList.contains(j)) {
                    continue;
                }
                integerList.add(j);
                System.out.println("第" + i + "排，第" + j + "列的座位已售出！");
            }
        }

        // 已经卖出的座位
        for (Map.Entry<String, List<Integer>> stringListEntry : cacheMap.entrySet()) {
            System.out.print("第" + stringListEntry.getKey() + "行座位卖出情况：");
            System.out.println(stringListEntry.getValue().toString());
        }
    }
}
